package com.google.libgdxpractice;

import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

public class MyWorld {

	public Rectangle ground;
	public World world;
	public Body groundBody;
	public Body boxBody;

	public MyWorld() {
		world = new World(new Vector2(0, -30), true);
		createBox();
		createGround();
	}
	
	private void createBox() {
        PolygonShape boxPoly = new PolygonShape();
        boxPoly.setAsBox(64, 32);
        BodyDef boxBodyDef = new BodyDef();
        boxBodyDef.type = BodyType.DynamicBody;
        boxBodyDef.position.x = 0;
        boxBodyDef.position.y = 0;
        boxBody = world.createBody(boxBodyDef);
        boxBody.createFixture(boxPoly, 20);
        boxBody.setTransform(new Vector2(50,200), 25);
        boxBody.setActive(true);
	}
	
	private void createGround() {
        PolygonShape groundPoly = new PolygonShape();
        groundPoly.setAsBox(240, 16);
        BodyDef groundBodyDef = new BodyDef();
        groundBodyDef.type = BodyType.StaticBody;
        groundBody = world.createBody(groundBodyDef);
        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.shape = groundPoly;
        fixtureDef.filter.groupIndex = 0;
        groundBody.createFixture(fixtureDef);
        groundPoly.dispose();
	}



	public void update(float deltaTime) {
	}

	public void step(float deltaTime, int i, int j) {
		world.step(deltaTime, i, j);		
	}

}